//
//  WLCTextField.m
//  HRD_Dev
//
//  Created by Mr.Dynasty on 2018/2/24.
//  Copyright © 2018年 Mr.Dynasty. All rights reserved.
//

#import "WLCTextField.h"

@interface WLCTextField ()<UITextFieldDelegate>

@property (strong, nonatomic) UIImageView *backImageView;



@end

@implementation WLCTextField

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self makeView];
    }
    return self;
}

- (void)makeView {
    
    _textField = [[UITextField alloc] init];
    [self addSubview:_textField];
    
    _leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    
    [_textField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    
    _leftBtn.frame = CGRectMake(0, 0, 30, 50);
    _rightBtn.frame = CGRectMake(0, 0, 30, 50);
//    _leftBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
//    _rightBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    _textField.leftView = _leftBtn;
    _textField.rightView = _rightBtn;
    _textField.leftViewMode = UITextFieldViewModeAlways;
    _textField.rightViewMode = UITextFieldViewModeWhileEditing;
    _textField.delegate = self;
}

- (void)setPlaceHolder:(NSString *)placeHolder {
    _placeHolder = placeHolder;
    NSMutableAttributedString *placeholder = [[NSMutableAttributedString alloc] initWithString:placeHolder];
    [placeholder addAttribute:NSForegroundColorAttributeName
                        value:PlaceHolderColor
                        range:NSMakeRange(0, placeHolder.length)];
    [placeholder addAttribute:NSFontAttributeName
                        value:RegularDefaultFont
                        range:NSMakeRange(0, placeHolder.length)];
    _textField.attributedPlaceholder = placeholder;
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    [self.textField becomeFirstResponder];
    return YES;
}

@end
